package com.zhongli.devplatform.bean;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhongli.devplatform.utils.BeanCopierUtil;
import lombok.Data;

import java.util.List;

@Data
public class PageVO<T> {

    /**
     * 当前页
     */
    private long current = 1;
    /**
     * 总的记录数
     */
    private long total = 0;
    /**
     * 每页显示的条数
     */
    private long size = 10;
    /**
     * 结果集
     */
    private List<T> records;

    public static <T> PageVO convert(IPage page, Class<T> c) {
        PageVO<T> newPage = new PageVO<>();
        newPage.setCurrent(page.getCurrent());
        newPage.setSize(page.getSize());
        newPage.setTotal(page.getTotal());
        newPage.setRecords(BeanCopierUtil.copy(page.getRecords(), c));
        return newPage;
    }


    public static <T> PageVO convert(IPage page) {
        PageVO<T> newPage = new PageVO<>();
        newPage.setCurrent(page.getCurrent());
        newPage.setSize(page.getSize());
        newPage.setTotal(page.getTotal());
        return newPage;
    }


}
